package day01;

/**
 * @Author Stringzhua
 * @Date 2024/10/28 16:47
 * description:线程的优先级
 */
public class Test06 {
    public static void main(String[] args) {
        // 创建子线程：打印数字1-26
        Thread thread1 = new Thread("数字线程") {
            @Override
            public void run() {
                for (int i = 1; i <= 26; i++) {
                    System.out.println(Thread.currentThread().getName() + "打印=>" + i + "[" + Thread.currentThread().getPriority() + "]");
                }
            }
        };

        // 创建子线程：打印字母A-Z
        Thread thread2 = new Thread("字母线程") {
            @Override
            public void run() {
                for (char i = 'A'; i <= 'Z'; i++) {
                    System.out.println(Thread.currentThread().getName() + "打印=>" + i + "[" + Thread.currentThread().getPriority() + "]");
                }
            }
        };

        thread1.setPriority(8); // 设置数字线程优先级=8
        thread2.setPriority(1); // 设置字母线程优先级=1

        // 启动子线程
        thread1.start();
        thread2.start();
    }
}
